<template>
    <div class="edu-page-warp">
        <div class="">
            <condition-card
                :class="plateId == 2?'queryClass':null"
                style="position: relative;"
                label-width="110px"
                label-position="right"
                @reset="reset"
                @search="searchList"
            >
                <!-- 预警信息 -->
                <el-row v-if="plateId == 2" class="binrow">
                    <el-col :span="16">
                        <div class="float-left">
                            劳动习惯养成学时预警：当前有{{
                                totalCount
                            }}位学生劳动习惯养成学时不足,其中{{ newCollegeCount }}为新生院学生！
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <el-button class="float-right" @click="btnDialog">查看名单</el-button>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item :label="$t('administrationClass.grade')">
                            <el-date-picker
                                v-model="queryForm.condition.grade"
                                :placeholder="$t('graduationDesign.pleaseChoose')"
                                class="search-item"
                                clearable
                                value-format="yyyy"
                                type="year"
                                style="width: 100%;"
                                @change="gradeChange"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('administrationClass.college')">
                            <el-select
                                v-model="queryForm.condition.college"
                                clearable
                                filterable
                                style="width:100%"
                                @change="collegeChange"
                            >
                                <el-option
                                    v-for="item in options.college"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('administrationClass.major')">
                            <el-select
                                v-model="queryForm.condition.major"
                                clearable
                                filterable
                                style="width:100%"
                            >
                                <el-option
                                    v-for="item in options.major"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.schoolTerm')">
                            <CalendarSelect
                                :defaulted="false"
                                v-model="queryForm.condition.calendarId"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="项目名称">
                            <el-input
                                v-model="queryForm.condition.name"
                                type="text"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" class="formclass">
                        <el-form-item label="学时">
                            <el-col :span="11">
                                <el-form-item prop="min">
                                    <el-input
                                        v-model="queryForm.condition.min"
                                        type="number"
                                        min="0"
                                        placeholder="请输入"
                                        onkeyup="value=value.replace(/[^\d.]/g,'')"
                                    />
                                </el-form-item>
                            </el-col>
                            <el-col :span="2" class="line">-</el-col>
                            <el-col :span="11">
                                <el-form-item prop="max">
                                    <el-input
                                        v-model="queryForm.condition.max"
                                        type="number"
                                        min="0"
                                        placeholder="请输入"
                                        onkeyup="value=value.replace(/[^\d.]/g,'')"
                                    />
                                </el-form-item>
                            </el-col>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="活动日期">
                            <el-date-picker
                                v-model="queryForm.condition.activityDate"
                                :placeholder="$t('graduationDesign.pleaseChoose')"
                                class="search-item"
                                clearable
                                value-format="yyyy-MM-dd"
                                type="date"
                                style="width: 100%;"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="最后修改时间">
                            <el-date-picker
                                v-model="queryForm.condition.lastModifyDate"
                                :placeholder="$t('graduationDesign.pleaseChoose')"
                                class="search-item"
                                clearable
                                value-format="yyyy-MM-dd"
                                type="date"
                                style="width: 100%;"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </condition-card>
            <el-card shadow="never">
                <div class="edu-page-title">{{ titel_label }}</div>
                <div class="edu-opertion-bar">
                    <div class="float-left">
                        <KeywordInput
                            v-model="queryForm.condition.studentName"
                            placeholder="请输入学号或姓名搜索"
                            @enter="searchList"
                        />
                    </div>
                    <div class="float-right">
                        <!-- 新增 -->
                        <el-button type="primary" @click="handleClick('ADD')">
                            {{ $t('common.btn.add') }}
                        </el-button>
                        <el-dropdown @command="handleCommand">
                            <el-button>
                                导入
                                <i class="el-icon-arrow-down el-icon--right" />
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item command="import">
                                    {{ $t('message.import') }}
                                </el-dropdown-item>
                                <el-dropdown-item command="download">
                                    {{ $t('message.down') }}
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                        <el-button @click="onExport">{{ $t('message.export') }}</el-button>
                        <el-button type="danger" @click="handleClick('MDEL')">删除</el-button>
                    </div>
                </div>
                <el-table
                    :order="false"
                    :selection="true"
                    :data="labourList"
                    @selection-change="handleSelectionChange"
                >
                    <el-table-column type="selection" width="50" />
                    <el-table-column
                        :label="$t('examinInquiry.studentNumber')"
                        prop="studentId"
                        fixed="left"
                        min-width="100"
                    />
                    <el-table-column
                        :label="$t('examinInquiry.fullName')"
                        prop="studentName"
                        show-overflow-tooltip
                        width="100"
                    />
                    <el-table-column :label="$t('examinInquiry.grade')" prop="grade" width="70" />
                    <el-table-column
                        :label="$t('examinInquiry.college')"
                        prop="collegeI18n"
                        show-overflow-tooltip
                        min-width="140"
                    />
                    <el-table-column
                        :label="$t('examinInquiry.major')"
                        :render-header="labelHead"
                        prop="majorI18n"
                        show-overflow-tooltip
                        min-width="110"
                    />
                    <el-table-column
                        :render-header="labelHead"
                        label="项目名称"
                        prop="name"
                        show-overflow-tooltip
                        min-width="140"
                    />
                    <el-table-column
                        :render-header="labelHead"
                        label="学时"
                        prop="hour"
                        show-overflow-tooltip
                        width="70"
                    />
                    <el-table-column
                        :render-header="labelHead"
                        label="活动日期"
                        prop="activityDate"
                        show-overflow-tooltip
                        width="110"
                    />
                    <el-table-column
                        :render-header="labelHead"
                        label="最后修改时间"
                        prop="updateTime"
                        show-overflow-tooltip
                        min-width="160"
                    />
                    <el-table-column :label="$t('message.operating')" fixed="right" width="110">
                        <template slot-scope="scope">
                            <div>
                                <el-button
                                    type="text"
                                    size="mini"
                                    @click.stop="handleClick('EDIT', scope.row)"
                                >
                                    {{ $t('message.edit') }}
                                </el-button>
                                <el-button
                                    type="text"
                                    size="mini"
                                    @click.stop="handleClick('DEL', scope.row)"
                                >
                                    {{ $t('message.delete') }}
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="edu-pagination">
                    <div class="float-right">
                        <el-pagination
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[10, 20, 50, 100, 500, 1000]"
                            :page-size="queryForm.pageSize_"
                            :total="total_"
                            layout="total, sizes, prev, pager, next, jumper"
                            style="float: right;margin:10px 60px 0 0;"
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                        />
                    </div>
                </div>
            </el-card>
            <!-- 弹框 -->
            <edu-dialog ref="updateDialog" :title="dialogTitle" :auto-height="true" width="600px">
                <el-form ref="createForm" :model="createForm" label-width="100px" label-suffix=":">
                    <el-row>
                        <!-- 学年学期 -->
                        <el-col :span="12">
                            <el-form-item
                                :label="$t('label.schoolTerm')"
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                            >
                                <CalendarSelect v-model="createForm.calendarId" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                label="板块"
                            >
                                <el-select
                                    v-model="plateId"
                                    clearable
                                    filterable
                                    disabled
                                    style="width:100%"
                                >
                                    <el-option
                                        v-for="item in plateIdList"
                                        :key="item.id"
                                        :label="item.label"
                                        :value="item.id"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                label="项目名称"
                                prop="name"
                            >
                                <el-input v-model="createForm.name" placeholder="" />
                            </el-form-item>
                        </el-col>
                        <!-- 学号 -->
                        <el-col :span="12">
                            <el-form-item
                                :label="$t('examinInquiry.studentNumber')"
                                :rules="[
                                    { required: true, message: $t('请输入数字'), trigger: 'blur' }
                                ]"
                                prop="studentId"
                            >
                                <el-input
                                    v-model="createForm.studentId"
                                    type="number"
                                    min="0"
                                    placeholder="请输入"
                                    onkeyup.native="value=value.replace(/[^\d.]/g,'')"
                                    @keyup.enter.native="blurFun"
                                    @blur="blurFun"
                                    @keyup.native="keyupFun"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                label="姓名"
                                prop="studentName"
                            >
                                <el-input
                                    v-model="createForm.studentName"
                                    disabled
                                    placeholder=""
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                label="年级"
                                prop="grade"
                            >
                                <el-input v-model="createForm.grade" disabled placeholder="" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                label="学院"
                                prop="collegeI18n"
                            >
                                <el-input
                                    v-model="createForm.collegeI18n"
                                    disabled
                                    placeholder=""
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :label="$t('label.major')"
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                prop="majorI18n"
                            >
                                <el-input v-model="createForm.majorI18n" disabled placeholder="" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    { required: true, message: $t('请输入数字'), trigger: 'blur' }
                                ]"
                                label="学时"
                                prop="hour"
                            >
                                <el-input
                                    v-model="createForm.hour"
                                    type="number"
                                    min="0"
                                    placeholder=""
                                    onkeyup.native="value=value.replace(/[^\d.]/g,'')"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                :rules="[
                                    {
                                        required: true,
                                        message: $t('message.inputRequired'),
                                        trigger: 'blur'
                                    }
                                ]"
                                label="活动日期"
                                prop="activityDate"
                            >
                                <el-date-picker
                                    v-model="createForm.activityDate"
                                    :placeholder="$t('graduationDesign.pleaseChoose')"
                                    class="search-item"
                                    clearable
                                    value-format="yyyy-MM-dd"
                                    type="date"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <span slot="buttons">
                    <el-button @click="close($event, createForm)">
                        {{ $t('message.cancel') }}
                    </el-button>
                    <el-button :disabled="btnTip" type="primary" @click="submitForm">
                        {{ $t('message.submit') }}
                    </el-button>
                </span>
            </edu-dialog>

            <edu-dialog
                ref="importDialog"
                :title="$t('message.import')"
                width="400px"
                @confirm="handleImportConfirm"
            >
                <el-row>
                    <el-col :span="24">
                        <el-form>
                            <el-row>
                                <el-col :span="8">
                                    <el-form-item :label="$t('label.schoolTerm')">
                                        <CalendarSelect v-model="calendarId" />
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="8">
                                    <el-form-item>
                                        <el-upload
                                            ref="upload"
                                            :data="{
                                                plateId: plateId,
                                                calendarId: calendarId
                                            }"
                                            :on-change="handleUploadChange"
                                            :on-error="handleUploadError"
                                            :on-success="handleUploadDone"
                                            :auto-upload="false"
                                            :multiple="false"
                                            :limit="1"
                                            :before-upload="beforeAvatarUpload"
                                            action="/api/scoremanagementservice/labourPracticeHour/import"
                                            accept=".xlsx,.xls"
                                        >
                                            <el-button slot="trigger" size="small" type="primary">
                                                {{ $t('label.selectFile') }}
                                            </el-button>
                                            <span slot="tip" style="margin-left:10px">
                                                只能上传.xls文件
                                            </span>
                                        </el-upload>
                                        <div
                                            v-if="showImportTip"
                                            style="position:absolute;color:red"
                                        >
                                            请上传导入文件!
                                        </div>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </el-col>
                </el-row>
            </edu-dialog>

            <!-- 预警查看名单plateId=2 -->
            <edu-dialog ref="warningDialog" title="查看名单" width="80%" class="earlywarning">
                <earlywarning ref="child" :plate-id="plateId" />
            </edu-dialog>
        </div>
    </div>
</template>
<script>
import api from 'common/src/api/score/bachelor/labourCourse'
import tools from 'common/src/views/underGraduationDesign/tools.js'
import earlywarning from './earlywarning'
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import mixin from 'common/src/mixins/index';
const defaultCreateForm = {
    studentId: null,
    studentName: null,
    professionI18n: null,
    grade: '',
    score: '',
    calendarId: '',
    hour: null
}

// 院聘导师库
export default {
    name: '',
    mixins: [mixin],
    components: {
        earlywarning
    },
    props: ['plateId', 'titel_label', 'totalCount', 'newCollegeCount'],
    data() {
        return {
            dialogTitle: '',
            multipleSelection: [],
            labourList: [],
            fileList: [], //导入文件
            showImportTip: false,
            mode: '',
            name: '',
            btnTip: false,
            btnTip2: false,
            rows: null,
            queryForm: {
                pageNum_: 1,
                pageSize_: 10,
                condition: {
                    grade: '', // 年级
                    college: '', // 学院
                    major: '', // 专业
                    min: null,
                    max: null,
                    page: true,
                    studentName: '',
                    calendarId: null, //学年学期
                    activityDate: null,
                    lastModifyDate: null
                }
            },
            calendarId: null,
            options: {
                college: [],
                major: []
            },
            plateIdList: [
                {
                    id: 2,
                    label: '劳动习惯养成学时管理'
                },
                {
                    id: 3,
                    label: '社会实践锻炼学时管理'
                },
                {
                    id: 4,
                    label: '公益志愿服务学时管理'
                },
                {
                    id: 5,
                    label: '创新创业提升学时管理'
                },
                {
                    id: 6,
                    label: '学校主题教育学时管理'
                },
                {
                    id: 7,
                    label: '学院特色实践学时管理'
                },
                {
                    id: 8,
                    label: '生活技能培养学时管理'
                }
            ],
            queryParams: {},
            message: '',
            createForm: UTILS.clone(defaultCreateForm)
        }
    },
    computed: {},
    watch: {
        'createForm.studentId'(newValue) {
            if (newValue && newValue.length > 16) {
                this.createForm.studentId = newValue.substring(0, 16)
            }
        },
        'createForm.name'(newValue) {
            if (newValue && newValue.length > 32) {
                this.createForm.name = newValue.substring(0, 32)
            }
        },
        'createForm.hour'(newValue) {
            let reg = /^\d+\.\d+$/ //是否是小数
            if (!reg.test(newValue) && newValue) {
                //不是小数
                if (newValue.length > 8) {
                    this.createForm.hour = newValue.substring(0, 8)
                }
            } else {
                if (newValue && newValue.split('.')[1] && newValue.split('.')[1].length > 2) {
                    this.createForm.hour = parseFloat(this.createForm.hour).toFixed(2)
                }
            }
        }
    },
    mounted() {
        this.queryForm.condition.grade = String(new Date().getFullYear())
        this.Scorelist()
        this.getOptions()
    },
    methods: {
        searchList() {
            if (
                parseFloat(this.queryForm.condition.min) > parseFloat(this.queryForm.condition.max)
            ) {
                this.$message('学时最小数不可大于最大数')
                return
            }
            this.Scorelist()
        },
        // 筛选条件字典查询
        Scorelist() {
            this.queryForm.condition.plateId = this.plateId
            api.labourLiftlist(this.queryForm).then(res => {
                if (res.code === 200) {
                    this.labourList = res.data.list
                    this.total_ = res.data.total_
                }
            })
        },
        // 重置筛选框
        reset() {
            this.queryForm = {
                pageNum_: 1,
                pageSize_: 10,
                condition: {
                    grade: String(new Date().getFullYear()), // 年级
                    college: '', // 学院
                    major: '', // 专业
                    min: null,
                    max: null,
                    page: true,
                    studentName: '',
                    calendarId: this.calendarCopy,
                    activityDate: null,
                    lastModifyDate: null
                }
            }
            this.options.major = []
            this.searchList()
        },
        keyupFun() {
            this.btnTip = true
        },
        //新增 输入学号带入学生信息 focusFun
        blurFun() {
            setTimeout(() => {
                if (this.createForm.studentId && !this.btnTip2) {
                    api.selectStudentInfoByStuId(this.createForm.studentId)
                        .then(res => {
                            if (res.code === 200) {
                                if (res.data) {
                                    this.btnTip = false
                                    //this.createForm = res.data;
                                    if (res.data.studentName) {
                                        this.createForm.studentName = res.data.studentName //姓名
                                    }
                                    if (res.data.grade) {
                                        this.createForm.grade = res.data.grade //年级
                                    }
                                    if (res.data.collegeI18n) {
                                        this.createForm.collegeI18n = res.data.collegeI18n //学院
                                    }
                                    if (res.data.majorI18n) {
                                        this.createForm.majorI18n = res.data.majorI18n //专业
                                    }
                                } else {
                                    if (this.createForm.studentId) {
                                        //this.$refs.updateDialog.open();
                                        this.btnTip = true
                                        this.createForm.studentName = ''
                                        this.createForm.grade = ''
                                        this.createForm.collegeI18n = ''
                                        this.createForm.majorI18n = ''
                                        this.$message({
                                            type: 'warning',
                                            message: '此学号不存在'
                                        })
                                        return
                                    }
                                }
                            }
                        })
                        .catch(e => {
                            console.log(e)
                        })
                }
            }, 300)
        },
        //新增 编辑 删除
        handleClick(mode, row) {
            this.btnTip = false
            this.btnTip2 = false
            this.mode = mode
            let copy = Object.assign({}, row)
            this.rows = copy
            switch (mode) {
                case 'ADD':
                    this.dialogTitle = this.$t('message.add')
                    this.createForm = UTILS.clone(defaultCreateForm)
                    this.createForm.calendarId = this.calendarCopy
                    this.$refs.updateDialog.open()
                    break
                case 'MDEL':
                    if (this.multipleSelection.length === 0) {
                        this.$message({
                            type: 'warning',
                            message: '请先勾选需要删除的列表记录'
                        })
                        return
                    }
                    this.$confirm('确认删除选中, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                        .then(() => {
                            api.labourLiftDel(this.multipleSelection.map(item => item.id)).then(
                                res => {
                                    if (res.code === 200) {
                                        this.$message({
                                            type: 'success',
                                            message: '删除成功!'
                                        })
                                        this.$refs.updateDialog.close()
                                        this.searchList()
                                    }
                                }
                            )
                        })
                        .catch(() => {})
                    break
                case 'DEL':
                    this.$confirm('确认删除, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        let ids = []
                        ids.push(row.id)
                        api.labourLiftDel(ids).then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                })
                                this.$refs.updateDialog.close()
                                this.searchList()
                            }
                        })
                    })
                    break
                case 'EDIT':
                    this.dialogTitle = this.$t('message.edit')
                    this.$refs.updateDialog.open()
                    this.TheoryDetails(row.id)
                    break
            }
        },
        //详情
        TheoryDetails(id) {
            api.labourLiftDetails(id).then(res => {
                if (res.code === 200) {
                    this.createForm = res.data
                }
            })
        },
        //添加保存
        submitForm() {
            this.$refs.createForm.validate(valid => {
                if (valid) {
                    if (this.createForm.hour < 0) {
                        this.$message('学时不能是负数')
                        return
                    }
                    let reg2 = /^\d{1,8}(\.\d{1,2})?$/ //是否是整数8位和小数2位
                    if (!reg2.test(parseFloat(this.createForm.hour))) {
                        this.$message('学时不可大于8位数')
                        return
                    }
                    if (this.mode === 'ADD') {
                        let data = {
                            calendarId: this.createForm.calendarId.toString(),
                            studentId: this.createForm.studentId,
                            plateId: this.plateId,
                            name: this.createForm.name,
                            hour: parseFloat(this.createForm.hour),
                            activityDate: this.createForm.activityDate
                        }
                        api.labourLiftAdd(data).then(res => {
                            if (res.code === 200) {
                                this.$refs.updateDialog.close()
                                this.searchList()
                                this.$message({ type: 'success', message: '成功' })
                            } else {
                                //this.$message({ type: 'error', message: res.msg })
                            }
                        })
                    } else if (this.mode === 'EDIT') {
                        let data = {
                            id: this.createForm.id,
                            calendarId: this.createForm.calendarId.toString(),
                            studentId: this.createForm.studentId,
                            plateId: this.plateId,
                            name: this.createForm.name,
                            hour: parseFloat(this.createForm.hour),
                            activityDate: this.createForm.activityDate
                        }
                        api.labourLiftedit(data).then(res => {
                            if (res.code === 200) {
                                this.$refs.updateDialog.close()
                                this.searchList()
                                this.$message({ type: 'success', message: '成功' })
                            } else {
                                //this.$message({ type: 'error', message: res.msg })
                            }
                        })
                    }
                }
            })
        },
        // 筛选条件字典查询
        getOptions() {
            let filter = false
            if(this.plateId == 7 && !this.global.isAdmin){                
                if(this.global.isAnyTeacher){
                    this.options.college.push({
                        label:this.global.currentUser.facultyName,
                        value:this.global.currentUser.faculty,
                    })
                    return
                }
                filter = true
            }
            let data = {
                    lang: this.$store.getters.language || 'cn',
                    type: 'allChild',
                    keys: ['X_YX']
            }
            queryDic(data).then(res => {
                UTILS.fillSelect({ college: 'X_YX' }, res.data, this.options)
                if(filter && this.global.isAcdemicDean){
                    if(this.global.currentUser.manageFaculty !== null && this.global.currentUser.manageFaculty !==''){
                        let manageFaculty = this.global.currentUser.manageFaculty.split(',')
                        this.options.college=this.options.college.filter(item=>manageFaculty.includes(item.value))
                    }else{
                        this.options.college=[{label:this.global.currentUser.facultyName,value:this.global.currentUser.faculty}]
                    }
                }
            })
        },
        //修改学院
        collegeChange(val) {
            this.options.major = []
            this.queryForm.condition.major = ''
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['G_ZY'],
                filter: {
                    grade: this.queryForm.condition.grade,
                    prefix: [val],
                    specilaCode: 'XY2ZY',
                    facultys: [val]
                }
            }
            queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        major: 'G_ZY'
                    },
                    res.data,
                    this.options
                )
            })
        },
        gradeChange(val) {
            this.options.major = []
            this.queryForm.condition.major = ''
            if (val && this.queryForm.condition.college) {
                this.collegeChange(this.queryForm.condition.college)
            }
        },
        close(event, data) {
            this.btnTip = false
            this.btnTip2 = true
            if (data.id) {
                //编辑
                this.closeDialog()
            } else {
                this.$refs.createForm.clearValidate()
                this.$refs.updateDialog.close()
                this.createForm.calendarId = this.calendarCopy
            }
        },
        closeDialog() {
            this.$refs.createForm.clearValidate()
            this.$refs.updateDialog.close()
        },
        resetAddForm() {
            this.btnTip = false
            this.$refs.createForm.clearValidate()
        },
        // 勾选
        handleSelectionChange(val) {
            this.multipleSelection = val
        },
        // 分页
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val
            this.searchList(this.queryForm)
        },
        // 分页
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val
            this.queryForm.pageNum_ = 1
            this.searchList(this.queryForm)
        },
        // 处理导入
        handleCommand(command) {
            if (command && command === 'import') {
                // 模板导入
                this.showImportTip = false
                this.$refs.importDialog.open()
                this.$refs.upload && this.$refs.upload.clearFiles()
                this.fileList = []
                //this.$refs.importBtn.click();
            } else if (command && command === 'download') {
                // 模板下载
                this.downloadTemplate()
            }
        },
        handleImportConfirm() {
            if (this.fileList.length === 0) {
                this.showImportTip = true
                return
            }
            this.$refs.upload.submit()
        },
        handleUploadChange(file, fileList) {
            this.fileList = fileList
            this.name = file.name
            if (this.fileList.length > 0) {
                this.showImportTip = false
            }
        },
        handleUploadError(err) {
            this.$message({
                type: 'error',
                duration: 5000,
                message: err
            })
        },
        //导入文件成功后
        handleUploadDone(res) {
            if (res.code === 200) {
                let loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(255, 255, 255, .48)'
                })
                this.delayImportRequest(res.data.key, loading)
            }
        },
        async delayImportRequest(key, loading) {
            await new Promise(resolve => setTimeout(resolve, 3000))
            api.getImportStatus(key)
                .then(res => {
                    if (res.code === 200 && res.data.status) {
                        loading.close()
                        if (res.data.success) {
                            this.$message({
                                type: 'success',
                                message: '导入成功'
                            })
                            this.$refs.importDialog.close()
                            this.searchList()
                        } else {
                            this.$refs.upload.clearFiles()
                            this.fileList.length = 0
                            let msg = res.data.msg || '导入失败'
                            this.$message({
                                type: 'error',
                                message: msg + ',请重新导入'
                            })
                        }
                    } else {
                        this.delayImportRequest(key)
                    }
                })
                .catch(() => {
                    this.delayImportRequest(key)
                })
        },
        beforeAvatarUpload(file) {
            const isLt2M = file.size / 1024 / 1024 < 10
            if (!isLt2M) {
                this.$message.error('导入文件大小不能超过10MB')
                this.$refs.upload.clearFiles()
                return false
            }
            if (file.name.substring(file.name.lastIndexOf('.')).toLowerCase() !== '.xls') {
                this.$message.error('导入文件错误')
                this.$refs.upload.clearFiles()
                return false
            }
        },
        // 导出
        onExport() {
            let data = _.cloneDeep(this.queryForm.condition)
            data.studentIds = this.multipleSelection.map(item => item.id)
            api.exportrPracticeHour(data).then(res => {
                if (res.code === 200) {
                    tools.downloadFile(res.data.key, `${this.titel_label + '.xls'}`, null, this)
                }
            })
        },
        // 模板下载
        downloadTemplate() {
            window.location.href = '/api/scoremanagementservice/labourPracticeHour/template'
        },
        // 预警
        btnDialog() {
            this.$refs.warningDialog.open()
            this.$nextTick(() => {
                this.$refs.child.queryForm.pageNum_ = 1
                this.$refs.child.queryForm.pageSize_ = 10 
                this.$refs.child.Scorelist()
            })
        },
        warning() {
            this.$refs.warningDialog.close()
        }
    }
}
</script>
<style lang="scss" scoped>
.edu-page-title {
    margin-bottom: 30px;
}
.line {
    text-align: center;
}
.binrow {
    width: 100%;
    padding: 30px 24px 0 34px;
    box-sizing: border-box;
    color: red;
    position: absolute;
    left: 0;
    top: 0;
}
.formclass > .el-form-item {
    height: 36px !important;
}
.comclass .queryClass ::v-deep .el-card__body {
    padding-top: 60px !important;
}
</style>
